<?php


include('./config.php');
//require_once ('jpgraph/jpgraph.php');
// Ex - http://deq2.bse.vt.edu/wooommdev/remote/plot_growth_trend.php?startyear=2008&endyear=2060&rate=0.009&startval=2.71
require_once ("$libpath/jpgraph/jpgraph_scatter.php");
 error_reporting(E_ALL);
 
$startyear=floatval($_GET['startyear']);
if (trim($startyear) == '') {
   $startyear = 2010;
}
$endyear=floatval($_GET['endyear']);
$rate=floatval($_GET['rate']);
$startval=floatval($_GET['startval']);
$numpoints = floatval($endyear - $startyear);
$data = array();

// Create some data points
$j = 0;
for($i= $startyear ; $i<= $endyear; ++$i) {
    //$datay[$i]= round(($startval * pow((1 + $rate),($i - $startyear))),2);
    $datay[$j]= round(($startval * pow((1 + $rate),($i - $startyear))),2);
	$xdata[$j] = $i;
	$j++;
    //print(" floatval($startval * (1 + $rate)^($i - $startyear)) = " . $j . " <br>");
}
 //print_r($datay);
 
// A format callbakc function
function mycallback($l) {
    return sprintf("%02.2f",$l);
}
 
// Setup the basic parameters for the graph
$graph = new Graph(400,200);
$graph->SetScale("intlin");
$graph->SetShadow();
$graph->SetBox();
 
$graph->title->Set("Growth trend - $startval @ $rate%/yr");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
 
// Set format callback for labels
$graph->yaxis->SetLabelFormatCallback("mycallback");
 
// Set X-axis at the minimum value of Y-axis (default will be at 0)
$graph->xaxis->SetPos("min");    // "min" will position the x-axis at the minimum value of the Y-axis
 
// Extend the margin for the labels on the Y-axis and reverse the direction
// of the ticks on the Y-axis
$graph->yaxis->SetLabelMargin(12);
$graph->xaxis->SetLabelMargin(6);
$graph->yaxis->SetTickSide(SIDE_LEFT);
$graph->xaxis->SetTickSide(SIDE_DOWN);
$graph->xaxis->SetTickLabels($xdata);
 
// Create a new impuls type scatter plot
$sp1 = new ScatterPlot($datay);
$sp1->mark->SetType(MARK_SQUARE);
$sp1->mark->SetFillColor("red");
//$sp1->SetImpuls();
$sp1->SetColor("blue");
$sp1->SetWeight(1);
$sp1->mark->SetWidth(3);
 
$graph->Add($sp1);
 
$graph->Stroke();
 
?>